import socket

import json
import struct
sk=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sk.bind(('127.0.0.1',8000))
sk.listen()
conn,addr=sk.accept()

b_dic_file=conn.recv(4)
len_dic=struct.unpack('i',b_dic_file)[0]
file_str_dic=conn.recv(len_dic).decode('utf-8')
file_dic=json.loads(file_str_dic)
print(type(file_dic),file_dic)
with open('tcp2.html',mode='wb') as f:
    while file_dic['filesize']>0:
        content=conn.recv(1024)
        file_dic['filesize']-=len(content)
        f.write(content)
conn.close()
sk.close()




















